/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.its.dsw2.Bl;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import mx.its.dsw2.Enumerations.TransactionStatus;
import mx.itsc.ds2.Dao.ScholarshipDaoLocal;
import mx.itsc.ds2.model.Scholarship;

/**
 *
 * @author Juan Carlos
 */
@Stateless
public class scholarshipBl implements scholarshipBlLocal {
    @EJB
    private ScholarshipDaoLocal scholarshipDao;

    @Override
    public TransactionStatus agregate(Scholarship scholarship) {
        if (scholarshipDao.findDuplicity(scholarship)) {
            return TransactionStatus.INCOMPLETO;
        } else {
            scholarshipDao.create(scholarship);
            return TransactionStatus.COMPLETO;
        }
    }

    @Override
    public TransactionStatus remove(Scholarship scholarship) {
        if (scholarship.getId() == null || scholarshipDao.find(scholarship.getId())== null) {
            return TransactionStatus.INCOMPLETO;
        } else {
            scholarshipDao.remove(scholarship);
            return TransactionStatus.COMPLETO;
        }
    }

    @Override
    public TransactionStatus modify(Scholarship scholarship) {
        if (scholarship.getId() == null || scholarshipDao.find(scholarship.getId())== null) {
            return TransactionStatus.INCOMPLETO;
        } else {
            scholarshipDao.edit(scholarship);
            return TransactionStatus.COMPLETO;   
        }
    }

    @Override
    public List<Scholarship> findAll() {
        return scholarshipDao.findAll();
    }

    @Override
    public List<Scholarship> findByScholarship(Scholarship scholarship) {
        List<Scholarship> scholarshipList = scholarshipDao.findByScholarship(scholarship);
        List<Scholarship> finalScholarshipList = new ArrayList<Scholarship>();
        for (Scholarship scholarship1 : scholarshipList) {
            finalScholarshipList.add(scholarship1);
        }
        return finalScholarshipList;
    }

    @Override
    public Scholarship findById(int idScholarship) {
        return scholarshipDao.find(idScholarship);
    }
    
    
}
